//
// client.cpp for client in /home/taitai/rtyperoxxor/serveur
// 
// Made by yannis berrouag
// Login   <berrou_y@epitech.net>
// 
// Started on  Wed Jan 11 20:06:42 2012 yannis berrouag
// Last update Sat Jan 14 18:14:21 2012 yannis berrouag
//

#include "include.h"

struct tab gl_tab[] =
  {
    {"OK", 1},
    {"KO", 2},
    {"PLAYER_PSEUDO",3},
    {"CHOSE_MAP", 4},
    {"JOIN_GAME",5},
    {"LEFT_GAME",6},
    {"READY",7,},
    {"LAUNCH_GAME",8},
    {"GAME_PORT",9},
    {"FINISH_GAME",10},
    {"OBJ_DEST",11},
    {"OBJ_INF",12},
    {"USER_EVENT",13},
    {"PING", 14},
    {"IP", 15},
    {0,0},
  };

int	main(int ac, char **av)
{
  PortableSocket	_sock;
  _sock.connect("127.0.0.1", 4243);
 
  if (ac != 3)
    {
      std::cout << "usage : <commande> <value>" << std::endl;
      return 0;
    }
  struct NetPacket	packet;
  int i = 0;
  for (; gl_tab[i].value != 0; i++)
    if (strcmp(gl_tab[i].key, av[1]) == 0)
      {
	packet._header._slotType = gl_tab[i].value;
	std::cout << "found " << packet._header._slotType << std::endl;
	break;
      }
  if (gl_tab[i].value == 0)
    {
      std::cout << "mauvaise commande" << std::endl;
      exit(1);
    }
  packet._header._packetId = 0;
  packet._header._len = strlen(av[2]);
  strcpy(packet.data, av[2]);
  std::cout << av[1] << "slot : " << (int) packet._header._slotType << std::endl;
  std::cout << packet._header._len << std::endl;
  _sock.send((char *) &packet, sizeof(packet));
}
